package com.zbkj.dal.entity.user;

import cn.hutool.core.util.IdUtil;
import com.zbkj.dal.base.constants.OrderConstants;
import com.zbkj.dal.base.enums.BooleanEnums;
import com.zbkj.dal.common.utils.CrmebUtil;
import lombok.Data;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author JinXinyu
 * @date 2024-02-08 15:04:14
 */
@Data
@TableName("eb_user_quota_account")
public class UserQuotaAccount implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 用户id
     */
    @TableField("user_id")
    private Integer userId;

    /**
     * 额度账号
     */
    @TableField("quota_account")
    private String quotaAccount;

    /**
     * 额度等级
     */
    @TableField("quota_level")
    private Integer quotaLevel;

    /**
     * 额度总额
     */
    @TableField("quota_total")
    private BigDecimal quotaTotal;

    /**
     * 额度余额
     */
    @TableField("quota_balance")
    private BigDecimal quotaBalance;

    /**
     * 额度已用金额
     */
    @TableField("quota_used")
    private BigDecimal quotaUsed;

    /**
     * 是否启用
     */
    @TableField("is_enable")
    private Integer enable;

    /**
     * 是否已升级
     */
    @TableField("is_upgraded")
    private Integer upgraded;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    private LocalDateTime updateTime;

    /**
     * 是否删除
     */
    @TableField("is_deleted")
    private Integer deleted;

    public static UserQuotaAccount initAccount(Integer userId){
        UserQuotaAccount userQuotaAccount = new UserQuotaAccount();
        userQuotaAccount.setUserId(userId);
        userQuotaAccount.setQuotaAccount(CrmebUtil.getAccountNo(OrderConstants.QUOTA_ACCOUNT_PREFIX, userId));
        userQuotaAccount.setQuotaLevel(1);
        userQuotaAccount.setQuotaTotal(BigDecimal.ZERO);
        userQuotaAccount.setQuotaBalance(BigDecimal.ZERO);
        userQuotaAccount.setQuotaUsed(BigDecimal.ZERO);
        userQuotaAccount.setEnable(BooleanEnums.TRUE.getCode());
        userQuotaAccount.setCreateTime(LocalDateTime.now());
        userQuotaAccount.setUpdateTime(LocalDateTime.now());
        userQuotaAccount.setDeleted(BooleanEnums.FALSE.getCode());
        return userQuotaAccount;
    }
}
